package Servlet;

import com.cyy.bean.product;
import com.cyy.dao.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/showProduct")
public class showProductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String message="";
        try {
            message = request.getAttribute("message").toString();
        }catch (Exception throwables){
            throwables.printStackTrace();
        }
        productDao productDao = new productDao();
        ArrayList<product> products = null;
        try {
            products = productDao.selectAll();
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }
        request.getSession().setAttribute("products", products);
        request.setAttribute("message",message);
        request.getRequestDispatcher("/salesmanProduct.jsp").forward(request, response);
        return;
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
